import remove from 'lodash/remove'

let relList = {
  'ADMIN': ['001', '011', '110', '111', '112', '113', '114', '012', '120', '121', '122', '123', '124', '013', '130', '131', '132', '133', '014', '140', '141', '142', '143', '002', '211', '2110', '212', '2120'],
  'MANAGER': ['001', '011', '110', '012', '120', '013', '130', '014', '140', '002', '211', '2110', '212', '2120'],
  'USER': [],
  'TESTROLE': []
}

export default {
  'get|/sys/role/relMenu': option => {
    let ret = {code: 200, msg: '', data: null}
    const url = option.url
    const roleId = url.split('/')[url.split('/').length - 1]
    const rel = relList[roleId]
    if (rel) {
      ret.data = rel
    } else {
      ret.code = 500
      ret.msg = '找不到角色Id为[' + roleId + ']的资源信息!'
    }
    return ret
  },
  'put|/sys/role/auth': option => {
    let ret = {code: 200, msg: '', data: null}
    const url = option.url
    const roleId = url.split('/')[url.split('/').length - 1]
    const params = JSON.parse(option.body)
    const removeList = params.remove
    const addList = params.add
    remove(relList[roleId], function (n) {
      return removeList.indexOf(n) > -1
    })
    relList[roleId] = relList[roleId].concat(addList)
    ret.msg = '成功!'
    return ret
  }
}
